package com.jiu345.api.controller;

import com.jiu345.api.pojo.GoodsSkus;
import com.jiu345.api.pojo.bo.GoodsBo;
import com.jiu345.api.pojo.vo.GoodsVo;
import com.jiu345.api.pojo.vo.GoodsItemVo;
import com.jiu345.core.page.PageQuery;
import com.jiu345.core.page.TableDataInfo;
import com.jiu345.api.pojo.Goods;
import com.jiu345.api.service.IGoodsService;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * package:GoodsCateController
 * @author MrLei QQ:235921049
 * @date 2024-05-21
 * desc:商品
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/mall/goods")
public class GoodsController extends BaseController {
    private final IGoodsService goodsService;


    /*TODO 根据SKU查询所有商品，本系统暂时不使用此方法*/
    @GetMapping("/sku")
    public TableDataInfo<GoodsSkus> sku(GoodsBo bo, PageQuery pageQuery){
        return goodsService.querySkuPageList(bo,pageQuery);
    }
    /*商品列表，主键*/
    @GetMapping("/list")
    public TableDataInfo<Goods> list(GoodsBo bo, PageQuery pageQuery){
        return goodsService.queryPageList(bo,pageQuery);
    }

    /*商品详情*/
    @GetMapping("/detail/{id}")
    public R<GoodsVo> getDetail(@NotNull(message = "主键不能为空")
                                   @PathVariable Long id){
        return R.ok(goodsService.getDetail(id));
    }
    /*TODO 根据SKU查询商品详情，本系统暂时不使用此方法*/
    @GetMapping("/item/{skuId}")
    public R<GoodsItemVo> getItem(@NotNull(message = "主键不能为空")
                                   @PathVariable Long skuId){
        return R.ok(goodsService.getSku(skuId));
    }

}
